/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import VO.CPulga;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author arturo
 */
public class CPulgaDao {

    public boolean Insertar(CPulga pulga) {
        boolean flag = false;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans = em.getTransaction();
        trans.begin();
        try {
            em.persist(pulga);
            trans.commit();
            flag = true;

        } catch (Exception ex) {
            trans.rollback();
        } finally {
            em.close();
        }
        return flag;



    }

    public boolean Actualizar(CPulga pulga) {
        boolean flag = false;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans = em.getTransaction();
        trans.begin();
        try {
            em.merge(pulga);
            trans.commit();
            flag = true;

        } catch (Exception ex) {
            trans.rollback();
        } finally {
            em.close();
        }
        return flag;



    }

    public boolean Eliminar(CPulga pulga) {
        boolean flag = false;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EjercicioJPAPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans = em.getTransaction();
        trans.begin();
        try {
            em.remove(em.merge(pulga));
            trans.commit();
            flag = true;

        } catch (Exception ex) {
            trans.rollback();
        } finally {
            em.close();
        }
        return flag;

    }
}
